package lab02.test06;

import java.util.Scanner;

public class Triangle {
    private double a;
    private double b;
    private double c;
    private double area;
    private double perimeter;
    boolean triangle;

    public double getA(){ return a; }

    public void setA(double a){this.a=a;}

    public double getB(){ return b; }

    public void setB(double b){this.b=b;}

    public double getC(){ return c; }

    public void setC(double c){this.c=c;}

    public void compose(){
        if (a+b>c&a+c>b&b+c>a){
            triangle=true;
        }else{
            triangle=false;
        }
        if (triangle==true){
            System.out.println("这三边："+a+"、"+b+"、"+c+"能构成一个三角形");
        }else{
            System.out.println("这三边："+a+"、"+b+"、"+c+"不能构成一个三角形");
        }
    }
    public void getArea(){
        double s=(a+b+c);
        area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
        System.out.println("三角形的面积为："+area);
    }
    public void getperimeter(){
        perimeter=a+b+c;
        System.out.println("三角形的周长为："+perimeter);
    }
    public void alter(){
        System.out.println("a、b、c三边需要修改么？（请输入是或者否）");
        Scanner sc=new Scanner(System.in);
        String m=sc.next();
        if (m.equals("是")){
            System.out.println("需要修改哪条边？a、b or c?");
            String n=sc.next();
            if (n.equals("a")){
                System.out.println("请输入修改后的值：");
                setA(sc.nextDouble());
            }else if (n.equals("b")){
                System.out.println("请输入修改后的值：");
                setA(sc.nextDouble());
            }else if (n.equals("c")){
                System.out.println("请输入修改后的值：");
                setA(sc.nextDouble());
            }
            compose();
            if(triangle==false){
                System.out.println("不能修改成该数值");
            }
        }
    }
}
